package com.mtnz.njk.Controller;

import com.mtnz.njk.Service.ExpressManagerService;
import com.mtnz.njk.entity.ExpressEntity;
import com.mtnz.njk.result.ResponseMessage;
import com.mtnz.njk.result.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @Description: 后台快递管理
 * @Author: FBL
 * @CreateDate: 2019\8\26 0026 8:19
 * @Version: 1.0
 */
@RestController
@RequestMapping("/express")
@CrossOrigin
public class ExpressManagerController {

    @Autowired
    ExpressManagerService expressManagerService;

    /**
     * 快递管理展示列表
     *
     * @param key
     * @param beginTime
     * @param endTime
     * @param pageNum
     * @param pageSize
     * @return
     * @throws Exception
     */
    @PostMapping("/listExpress")
    public ResponseResult listExpress(String key, String beginTime, String endTime, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) throws Exception {
        return expressManagerService.listExpress(key, beginTime, endTime, pageNum, pageSize);
    }

    /**
     * 快递管理编辑或新增
     *
     * @param expressEntity
     * @return
     * @throws Exception
     */
    @PostMapping("/updateOrInsertExpress")
    public ResponseResult updateOrInsertExpress(@RequestBody ExpressEntity expressEntity) throws Exception {
        return expressManagerService.updateOrInsertExpress(expressEntity);
    }

    /**
     * 快递管理删除
     *
     * @param expressId
     * @return
     * @throws Exception
     */
    @PostMapping("/delExpress")
    public ResponseResult delExpress(Integer expressId) throws Exception {
        if (expressId == null || ("").equals(expressId))
            return new ResponseResult(ResponseMessage.NULL_REQUEST);
        return expressManagerService.delExpress(expressId);
    }

    /**
     * 快递管理表格导出
     *
     * @return
     * @throws Exception
     */
    @GetMapping("/excelExpress")
    public ResponseResult excelExpress(HttpServletResponse response) throws Exception {
        return expressManagerService.excelExpress(response);
    }

}
